package com.todo.strategy.offline.application.backend.controller;

import com.todo.common.common.entity.response.BizPageResponse;
import com.todo.common.common.entity.response.BizResponse;
import com.todo.common.common.entity.response.page.PageResult;
import com.todo.common.common.enums.EnableTypeEnum;
import com.todo.strategy.offline.application.convert.MemoTemplateConvert;
import com.todo.strategy.offline.application.entity.bo.MemoTemplateBO;
import com.todo.strategy.offline.application.entity.condition.MemoTemplateConditionBO;
import com.todo.strategy.offline.application.service.MemoTemplateService;
import com.todo.strategy.offline.iface.MemoTemplateIface;
import com.todo.strategy.offline.iface.request.*;
import com.todo.strategy.offline.iface.response.MemoTemplateResp;
import com.todo.strategy.offline.iface.response.QueryMemoTemplateBaseResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2024/11/28 03:55
 * @description
 */
@RestController
@RequestMapping("/strategy/memo")
@Tag(name = "攻略备忘录后台处理类", description = "攻略备忘录后台处理类")
public class MemoTemplateController implements MemoTemplateIface {

    @Resource
    private MemoTemplateService memoTemplateService;

    @Override
    @Operation(summary = "新增备忘录模板信息")
    @PostMapping("/insertMemoTemplate")
    public BizResponse<Boolean> insertMemoTemplate(@RequestBody InsertMemoTemplateReq req) {
        if (req == null) {
            return BizResponse.paramError("参数为空");
        }
        if (!req.baseCheck()) {
            return BizResponse.paramError("参数错误");
        }
        MemoTemplateBO memoTemplateBO = MemoTemplateConvert.convertToMemoTemplateBO(req);
        Boolean insertResult = memoTemplateService.insertMemoTemplate(memoTemplateBO);
        return BizResponse.success(insertResult);
    }

    @Override
    @Operation(summary = "更新备忘录模板基础信息")
    @PostMapping("/updateMemoTemplate")
    public BizResponse<Boolean> updateMemoTemplate(@RequestBody UpdateMemoTemplateReq req) {
        if (req == null) {
            return BizResponse.paramError("参数为空");
        }
        if (!req.baseCheck()) {
            return BizResponse.paramError("参数错误");
        }
        MemoTemplateBO memoTemplateBO = MemoTemplateConvert.convertToMemoTemplateBO(req);
        Boolean updateResult = memoTemplateService.updateMemoTemplate(memoTemplateBO);
        return BizResponse.success(updateResult);
    }

    @Override
    @Operation(summary = "根据主键删除备忘录信息")
    @PostMapping("/removeMemoTemplateById")
    public BizResponse<Boolean> removeMemoTemplateById(@RequestBody RemoveMemoTemplateByIdReq req) {
        if (req == null) {
            return BizResponse.paramError("参数为空");
        }
        if (!req.baseCheck()) {
            return BizResponse.paramError("参数错误");
        }
        Boolean removeResult = memoTemplateService.removeMemoTemplateById(req.getId());
        return BizResponse.success(removeResult);
    }

    @Override
    @Operation(summary = "更新备忘录模板状态")
    @PostMapping("/updateMemoTemplateStatusById")
    public BizResponse<Boolean> updateMemoTemplateStatusById(@RequestBody UpdateMemoTemplateStatusByIdReq req) {
        if (req == null) {
            return BizResponse.paramError("参数为空");
        }
        if (!req.baseCheck()) {
            return BizResponse.paramError("参数错误");
        }
        Boolean updateResult = memoTemplateService.updateMemoStatusById(req.getId(), EnableTypeEnum.getByType(req.getOldStatus()), EnableTypeEnum.getByType(req.getNewStatus()));
        return BizResponse.success(updateResult);
    }

    @Override
    @Operation(summary = "根据主键查询备忘录详情信息")
    @PostMapping("/queryMemoTemplateById")
    public BizResponse<MemoTemplateResp> queryMemoTemplateById(@RequestBody QueryMemoTemplateDetailByIdReq req) {
        if (req == null) {
            return BizResponse.paramError("参数为空");
        }
        if (!req.baseCheck()) {
            return BizResponse.paramError("参数错误");
        }
        MemoTemplateBO memoTemplateBO = memoTemplateService.queryMemoTemplateById(req.getId());
        return BizResponse.success(MemoTemplateConvert.convertToMemoTemplateResp(memoTemplateBO));
    }

    @Override
    @Operation(summary = "多条件分页查询备忘录模板信息")
    @PostMapping("/queryMemoTemplateByCondition")
    public BizPageResponse<QueryMemoTemplateBaseResp> queryMemoTemplateByCondition(@RequestBody QueryMemoTemplateBaseReq req) {
        if (req == null) {
            return BizPageResponse.paramError("参数为空");
        }
        if (!req.baseCheck()) {
            return BizPageResponse.paramError("参数错误");
        }
        MemoTemplateConditionBO conditionBO = MemoTemplateConvert.convertToMemoTemplateConditionBO(req);
        PageResult<MemoTemplateBO> pageResult = memoTemplateService.queryMemoTemplateByPage(conditionBO);
        return BizPageResponse.success(MemoTemplateConvert.convertToPageQueryMemoTemplateBaseResp(pageResult));
    }
}
